<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt"%>
<!-- 地下面积 -->
<form class="cmxform" id="commentFormbua" method="get" action="" onsubmit="return false;" >
	<div style="padding:0px">

		<div class="panel panel-default">
			<div class="panel-heading">
				<h5 class="panel-title">基本信息</h5>
			</div>
			<div class="panel-body">
				<!-- 地下面积start-->
				<div class="style_border_bottom">
					<span class="style_btn" style="margin-right: 15px;">总建筑面积</span>
					<input id="allBuildingArea" name="allBuildingArea" value="<fmt:formatNumber value="${buildingUnderArea.allBuildingArea }" pattern="##0.00"/>"/> ㎡
				</div>
				<table class="mytable">
					<tr class="style_border_bottom">
						<td width="100"><span class="style_btn">设备间面积</span></td>
						<td><input id="facilityArea" name="facilityArea" value="<fmt:formatNumber value="${buildingUnderArea.facilityArea }" pattern="##0.00"/>"/> ㎡</td>
					</tr>
					<tr class="style_border_bottom">
						<td><span class="style_btn">存储面积</span></td>
						<td><input id="storageArea" name="storageArea" value="<fmt:formatNumber value="${buildingUnderArea.storageArea }" pattern="##0.00"/>"/> ㎡</td>
					</tr>
					<tr class="style_border_bottom">
						<td><span class="style_btn">车场面积</span></td>
						<td><input id="carParkArea" name="carParkArea" value="<fmt:formatNumber value="${buildingUnderArea.carParkArea }" pattern="##0.00"/>"/> ㎡</td>
					</tr>
					<tr class="style_border_bottom">
						<td><span class="style_btn">人防面积</span></td>
						<td><input id="personDefenceArea" name="personDefenceArea" value="<fmt:formatNumber value="${buildingUnderArea.personDefenceArea }" pattern="##0.00"/>"/>
							㎡</td>
					</tr>
					<tr>
						<td><span class="style_btn">公共面积</span></td>
						<td><input id="publicArea" name="publicArea" value="<fmt:formatNumber value="${buildingUnderArea.publicArea }" pattern="##0.00"/>"/> ㎡</td>
					</tr>
				</table>
				<!-- 地下面积end-->
			
			</div>
		</div>
		<div style="width:100%;text-align:center; padding-top:20px">
			<%-- <c:choose>
				<c:when test="${empty requestScope.buildingUnderArea}">
					<button class="btn btn-danger radius my-btn"
						onclick="saveUnderground(0)" type="button">提交</button>
					<button class="btn btn-danger radius my-btn"
						onclick="saveUnderground(1)" type="button">保 存</button>
					<button class="btn btn-default radius"  onclick="resetForms('commentFormbua')" >
						重置 </button>
					<br />
				</c:when>
				<c:otherwise>
					<button id="modifyBtn" class="btn btn-danger radius my-btn"
						onclick="saveUnderground(3)" type="button">启用编辑</button>
					<button class="btn btn-danger radius my-btn hidbtn"
						onclick="saveUnderground(2)" type="button">保存修改</button>
					<button class="btn btn-default radius hidbtn" onclick="resetForms('commentFormbua')" >
						重置 </button>	
				</c:otherwise>
			</c:choose> --%>
			<div id="div_b1" style="dispaly:none;">
					<button class="btn btn-danger radius my-btn"
						onclick="saveUnderground(0)" type="button">提交</button>
					<button class="btn btn-danger radius my-btn"
						onclick="saveUnderground(1)" type="button">保 存</button>
					<button class="btn btn-default radius"  onclick="resetForms('commentFormbua')" >
						重置 </button>
			</div>
			<div id="div_b2" style="dispaly:none;">
					<br />
				<shiro:hasPermission name="permission:edit">
					<button id="modifyBtn" class="btn btn-danger radius my-btn"
						onclick="saveUnderground(3)" type="button">启用编辑</button>
					<button class="btn btn-danger radius my-btn hidbtn"
						onclick="saveUnderground(2)" type="button">保存修改</button>
					<button class="btn btn-default radius hidbtn" onclick="resetForms('commentFormbua')" >
						重置 </button>
				</shiro:hasPermission>
			</div>	
		</div>
		<input type="hidden" id="entityId_buaId" name="id" value="${buildingUnderArea.id }"/>
	</div>
</form>
<script type="text/javascript">
	$(function(){
		//如果已经保存过了，则开启只读状态
		<c:if test="${not empty requestScope.buildingUnderArea }">
			$("#commentFormbua").find("input,textarea").attr("readonly",true);
		</c:if>
		var obj = '${buildingUnderArea}';
		if(obj==null || obj==="" ||obj==undefined){
			$("#commentFormbua #div_b1").show();
			$("#commentFormbua #div_b2").hide();
		}else{
			$("#commentFormbua #div_b1").hide();
			$("#commentFormbua #div_b2").show();
		}
	});
	
	
	var optUnderArea;
	//optFloorNum操作字段，0：临时保存；1：新增；2：修改
	function saveUnderground(val){
		optUnderArea=val;
		if(val==3){
			//解除锁定状态
			var index=layer.confirm('确定开启编辑状态？', {
			 	offset:'20%',
				shade:0
			}, function(){
			  //去除只读开启按钮编辑
			   $("#commentFormbua").find("input,textarea").attr("readonly",false);
			   $("#commentFormbua #modifyBtn").hide();
			  // $(".hidbtn").removeClass("hidbtn");
			  $("#commentFormbua .hidbtn").addClass("showbtn");
			   layer.close(index);
			});
		}else{
			saveBottomArea(optUnderArea);
		}
	}
	var pi;
	function saveBottomArea() {
		pi=layer.load(2);
		var id = $("#entityId_buaId").val();
		var facilityArea = $("#facilityArea").val();
		var storageArea = $("#storageArea").val();
		var carParkArea = $("#carParkArea").val();
		var personDefenceArea = $("#personDefenceArea").val();
		var publicArea = $("#publicArea").val();
		var allBuildingArea=$("#allBuildingArea").val();
		if(!testNum(allBuildingArea)){
			layer.msg("总建筑面积请输入数值");
			$("#allBuildingArea").focus();
			layer.close(pi);
		}else if (!testNum(facilityArea)) {
			layer.msg("设备间面积请输入数值");
			$("#facilityArea").focus();
			layer.close(pi);
		}else if (!testNum(carParkArea)) {
			layer.msg("车场面积请输入数值");
			$("#carParkArea").focus();
			layer.close(pi);
		} else if (!testNum(storageArea)) {
			layer.msg("存储面积请输入数值");
			$("#storageArea").focus();
			layer.close(pi);
		}  else if (!testNum(personDefenceArea)) {
			layer.msg("人防面积请输入数值");
			$("#personDefenceArea").focus();
			layer.close(pi);
		} else if (!testNum(publicArea)) {
			layer.msg("公共面积请输入数值");
			$("#publicArea").focus();
			layer.close(pi);
		} else {
			var url = "house/UndergroundArea/add";
			jQuery.ajax({
				type : "post",
				async : false,
				url : url,
				dataType : "json",
				data : {
					fkBuildingArea : '${requestScope.buildingNum.buildingArea }',
					allBuildingArea : allBuildingArea,
					facilityArea : facilityArea,
					storageArea : storageArea,
					carParkArea : carParkArea,
					personDefenceArea : personDefenceArea,
					publicArea : publicArea,
					id:id,
					opt:optUnderArea
				},
				success : function(responseText) {
					layer.close(pi);
					if (responseText.success) {
						layer.alert('保存成功！',{
							offset:'20%',
							shade:0
						},function(){
							layer.close(pi);
							parent.tabShow=1;
							parent.tabTypeShow=0;
							location.reload();
							//显示当前tab
							//$("#area_tab [role='tablist'] li:eq(1) a").tab("show");
						});
					} else {
						layer.msg('保存失败！');
						layer.closeAll();
					}
				}
			});
		}

	}
</script>

